package cn.iocoder.yudao.module.handguard.service.userbasetable10;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable10.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable10.UserBaseTable10DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable10.UserBaseTable10Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable10.UserBaseTable10Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 商业写字楼按揭贷款 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable10ServiceImpl implements UserBaseTable10Service {

    @Resource
    private UserBaseTable10Mapper userBaseTable10Mapper;

    @Override
    public Long createUserBaseTable10(UserBaseTable10CreateReqVO createReqVO) {
        // 插入
        UserBaseTable10DO userBaseTable10 = UserBaseTable10Convert.INSTANCE.convert(createReqVO);
        userBaseTable10Mapper.insert(userBaseTable10);
        // 返回
        return userBaseTable10.getId();
    }

    @Override
    public void updateUserBaseTable10(UserBaseTable10UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable10Exists(updateReqVO.getId());
        // 更新
        UserBaseTable10DO updateObj = UserBaseTable10Convert.INSTANCE.convert(updateReqVO);
        userBaseTable10Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable10(Long id) {
        // 校验存在
        validateUserBaseTable10Exists(id);
        // 删除
        userBaseTable10Mapper.deleteById(id);
    }

    private void validateUserBaseTable10Exists(Long id) {
        if (userBaseTable10Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE10_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable10DO getUserBaseTable10(Long id) {
        return userBaseTable10Mapper.selectById(id);
    }

    @Override
    public List<UserBaseTable10DO> getUserBaseTable10List(Long userId) {
        LambdaQueryWrapper<UserBaseTable10DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable10DO::getApplicationId,userId);
        return userBaseTable10Mapper.selectList(queryWrapper);
    }

    @Override
    public PageResult<UserBaseTable10DO> getUserBaseTable10Page(UserBaseTable10PageReqVO pageReqVO) {
        return userBaseTable10Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable10DO> getUserBaseTable10List(UserBaseTable10ExportReqVO exportReqVO) {
        return userBaseTable10Mapper.selectList(exportReqVO);
    }

}
